package com.ws.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import com.ws.interceptor.LoginInterceptor;
@Configuration
public class EasyWebConfig implements WebMvcConfigurer{
	public static final String  STATIC_PATH = "/img/";
	public static final String STATIC_DIR = "D:\\uploadfile\\";
	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		
		registry.addResourceHandler(STATIC_PATH + "**").addResourceLocations("file:" + STATIC_DIR);
		
	}
	/**
	 * 配置拦截器  让拦截器生效
	 */
	@Autowired
	LoginInterceptor loginInterceptor;
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		/*
		 * addInterceptor放想要使用的拦截器对象
		 * addPathPatterns放要拦截的mapping地址
		 * excludePathPatterns放不需要拦截的mapping地址
		 */
		registry.addInterceptor(loginInterceptor).addPathPatterns("/**").excludePathPatterns("/dologin","/img/**","/staff/upload","/send-mail/**");
	}
}
